function [voxels diams] = XGlom_CC_Stats(CC)
%% Statistics and analyses of the connected component struct, CC.
% This function analyses the output of bwconncomp to return 
% overall statistics about the number of voxels and estimated diameter
% of the components
%

%
%   - Michael Eager,   (michael.eager@monash.edu) 
%   - (c) 2012, Monash Biomedical Imaging, Monash University, Australia

%     Copyright © 2012-2013 Michael Eager <michael.eager@monash.edu> 
%
%     This file is part of Xglom.
% 
%     This is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/>.


%calculate area histogram
    areas = cellfun(@numel,CC.PixelIdxList);
    area_max = 1000; %max(areas);
    area_range=(1:area_max);
    [voxels, area_axis]=hist(areas,area_max);
    

    %Total number of detected objects in area_range
    %['sum(area_hist(12:100)):  ', num2str(sum(area_hist))];
    
    %Diameter histogram from area data assuming spherical glomeruli
    [diams x]=hist((6/pi*voxels).^(1/3),1:0.1:15); 
